﻿--[[
   @brief    super_mult_account_mgr view  -- AKA 超级多开
   @author   maxyao
   @version  1.0
   @date     2017-03-14
--]]

super_multi_account_mgr_view = {
    init = function ()
    --[[
        event_center.add_listener(mult_account_event.MULT_ACCOUNT_UPDATE_LIST,
            'mult_account_view.update_account_info');

        event_center.add_listener(mult_account_event.MULT_ACCOUNT_GAME_STATE,
            'mult_account_view.update_account_state');

        event_center.add_listener(mult_account_event.MULT_ACCOUNT_ACCOUNT_WARNING,
            'mult_account_view.show_account_warning_tips');

        event_center.add_listener(mult_account_event.MULT_ACCOUNT_ACCOUNT_WARNING_HIDE,
            'mult_account_view.hide_account_warning_tips');
            ]]
        ierd_tgp.tpf_ui.Require('super_multi_account_mgr\\model.lua');
        ierd_tgp.tpf_ui.Require('super_multi_account_mgr\\view.lua');
    end;

    open = function(game_id)
        super_multi_account_mgr_model.show_dlg = true
        super_multi_account_mgr_model.cur_game_id = game_id;
        base_utility.log("[super_multi_account_mgr_view] show window.");
        super_multi_account_mgr_control.report_operation(
            super_multi_account_mgr_model.op_type.OP_OPEN_SUPER_MULTI_ACCOUNT_DLG,
            super_multi_account_mgr_model.primary_uin);
    end;



    load_web_page = function()
        base_utility.log("[super_multi_account_mgr_view] load_web_page");
        local pControl = ui_utility.get_ctrl_ptr_by_cid(CID_SUPER_MULT_ACCOUNT_QBWEB);
        if nil ~= pControl then
            local pQBWeb = tolua.cast(pControl, "Tenio::IQBWebBrowser");
            local  game_id = super_multi_account_mgr_model.cur_game_id;
            local max_launch_count = super_multi_account_mgr_control.get_max_launch_account(game_id);
            local url = 
                super_multi_account_mgr_model.super_multi_account_mgr_page_url
                 .. "?game_id=" .. game_id .. "&max_launch_count=" .. max_launch_count;
            local const_ui_str = U8toCUIStr(url);
            pQBWeb:Navigate(const_ui_str);
        end;
    end;

    show_page = function()
        base_utility.log("[super_mult_account_mgr_view] show_page");
        local nPageDlg = ui_utility.get_ctrl_id_by_cid(CID_SUPER_MULT_ACCOUNT_DLG);
        if nPageDlg == Tenio.INVALID_CONTROLID then
            return;
        end;
        local pPageDlg = ui_utility.get_ctrl_ptr_by_cid(CID_SUPER_MULT_ACCOUNT_DLG);
        if (nil ~= pPageDlg) then
            pPageDlg:MoveToCenter(); 
            pPageDlg:Show(TRUE);
            pPageDlg:BringToTop();
            pPageDlg:SetFocus();
        end;
    end;

    show_web_ctn = function(bshow)
        local nPageDlg = ui_utility.get_ctrl_id_by_cid(CID_SUPER_MULT_ACCOUNT_QBWEB);
        if Tenio.INVALID_CONTROLID == nPageDlg then
            return;
        end;

        if bshow == true then
            ui_utility.setproperty_by_id(nPageDlg, "Visible", "true");
        else
            ui_utility.setproperty_by_id(nPageDlg, "Visible", "false");
        end
    end;

    close = function(uilib, id)
        local pPageDlg = ui_utility.get_ctrl_ptr_by_cid(CID_SUPER_MULT_ACCOUNT_DLG);
        if (nil ~= pPageDlg) then
            pPageDlg:Show(FALSE);
        end;
        local nPageDlg = ui_utility.get_ctrl_id_by_cid(CID_SUPER_MULT_ACCOUNT_DLG);
        if nPageDlg ~= Tenio.INVALID_CONTROLID then
            layout_mgr.delay_remove_ctrl(nPageDlg);
        end
        base_utility.log("[super_multi_account_mgr_view] close dlg");
        super_multi_account_mgr_control.report_operation(
            super_multi_account_mgr_model.op_type.OP_CLOSE_SUPER_MULTI_ACCOUNT_DLG,
            super_multi_account_mgr_model.primary_uin);
    end;

}

super_multi_account_mgr_view.init();